Factor out iteration over slices since it can be used in other reprojection algorithms