distance matrix bounds stn filter function