some fixes and improvements in cv::matchTemplate