minor perf improvement for matchTemplate