import torch


def filter_points(points, shape):
    """
        Remove points laying out of the image shape
    """
    shape_tensor = torch.tensor(shape, dtype=torch.float) - 1
    mask = (points >= 0) & (points <= shape_tensor)
    mask = torch.all(mask, dim=1)
    filtered = points[mask]
    return filtered