add a filter parameter to nearest function

filter is an evaluation function that receives the node to evaluate and returns the result of the evaluation, true or false.