This probably needs some javadoc explaining threshold and distanceTolerance parameter.