added thresholding code for matches