How to template match inside a contour?

I have an image that contains multiple rectangular contours. I also have 44 different templates that I would like to match inside each contour, however, each contour would contain at most 3 matches and minimum 1 match. How do I attempt to match 44 templates inside each contour with a high probability of matching the correct templates? My thought process was to create a binary mask and look inside each rectangle then attempt to match but I am having difficulty even getting the mask correctly.

This snippet of code came from inside my contour loop.

#Creating mask to look inside rectangles
blockMask = np.zeros(srcImg.shape[:2], dtype="uint8")
if(numberVert == 4):
    #Creating a mask to retrieve only what is inside the block
    blockMask = cv2.rectangle(blockMask, (rx, ry), (rx + rw, ry + rh), (255, 255, 255), FILLED)
    #ANDing it with the inverted color filtered image mask
    blockMask = cv2.bitwise_and(cv2.bitwise_not(imgMask), blockMask)
    #Checking inside the templates list to see which image template matches
    for t in range(len(templates)):
        imgTemp = templates[t]
        #Getting the template width and height
        iw, ih = imgTemp.shape[::-1]
        #Attempting to match template to what is inside the blockMask
        res = cv2.matchTemplate(blockMask, imgTemp, cv2.TM_CCOEFF_NORMED)
        #Defined a threshold to establish a baseline for what may be a match
        tempThresh = 0.65
        #Get location where the match is greater than the threshold
        loc = np.where(res >= tempThresh)
        for pt in zip(*loc[::-1]):
            #Draw possible matches
            cv2.rectangle(srcImg, pt, (pt[0] + iw, pt[1] + ih), (0,0,0), 2)

related: python - How to template match inside a contour? - Stack Overflow

I made that post as well, I’m just trying to broaden the possibilities of replies.