I tried very quickly your code and it seems that:
- the detection of the top right template is missing
- I think that the threshold (0.8) in your first while loop is too low: I don't know why but at the scale where there are hits at thresh=0.8, the correlation for the top right zone is a little lower than 0.8 and you miss this detection
- check if at the scale where you have hits at 0.8, the template scale is the same than in the reference image
- if you choose 0.85 in the first while loop, you will have the 3 detections
- I may be wrong but the match template between the 2 while loops is useless for me ?
Hope this help you a little bit.