Nonlocal thresholds for improving the spatial resolution of pixel detectors