result = cv2.matchTemplate(img, template, cv.CV_TM_SQDIFF)
min_x, max_y, minloc, maxloc = cv2.minMaxLoc(result)
x, y = minloc
result2 = np.reshape(result, result.shape[0] * result.shape[1])
sort = np.argsort(result2)
opencv python MatchTemplate function with multiple matches