def METHOD_NAME(self, outputs, targets):
    """ Performs the matching
    Params:
        outputs: A dict that contains at least these entries:
             "pred_is_referred": Tensor of dim [time, batch_size, num_queries, 2] with the reference logits
             "pred_masks": Tensor of dim [time, batch_size, num_queries, H, W] with the predicted masks logits
        targets: A list of lists of targets (outer - time steps, inner - batch samples). each target is a dict
                 which contain mask and reference ground truth information for a single frame.
    Returns:
        A list of size batch_size, containing tuples of (index_i, index_j) where:
            - index_i is the indices of the selected predictions (in order)
            - index_j is the indices of the corresponding selected targets (in order)
        For each batch element, it holds:
            len(index_i) = len(index_j) = min(num_queries, num_target_masks)
    """
    t, bs, num_queries = outputs['pred_masks'].shape[:3]
    # We flatten to compute the cost matrices in a batch
    out_masks = outputs['pred_masks'].flatten(
        1, 2)  # [t, batch_size * num_queries, mask_h, mask_w]
    # preprocess and concat the target masks
    tgt_masks = [[
        m for v in t_step_batch for m in v['masks'].unsqueeze(1)
    ] for t_step_batch in targets]
    # pad the target masks to a uniform shape
    tgt_masks, valid = list(
        zip(*[
            nested_tensor_from_tensor_list(t).decompose()
            for t in tgt_masks
        ]))
    tgt_masks = torch.stack(tgt_masks).squeeze(2)
    # upsample predicted masks to target mask size
    out_masks = interpolate(
        out_masks,
        size=tgt_masks.shape[-2:],
        mode='bilinear',
        align_corners=False)
    # Compute the soft-tokens cost:
    if self.cost_is_referred > 0:
        cost_is_referred = compute_is_referred_cost(outputs, targets)
    else:
        cost_is_referred = 0
    # Compute the DICE coefficient between the masks:
    if self.cost_dice > 0:
        cost_dice = -dice_coef(out_masks, tgt_masks)
    else:
        cost_dice = 0
    # Final cost matrix
    C = self.cost_is_referred * cost_is_referred + self.cost_dice * cost_dice
    C = C.view(bs, num_queries, -1).cpu()
    num_traj_per_batch = [
        len(v['masks']) for v in targets[0]
    ]  # number of instance trajectories in each batch
    indices = [
        linear_sum_assignment(c[i])
        for i, c in enumerate(C.split(num_traj_per_batch, -1))
    ]
    device = out_masks.device
    return [(torch.as_tensor(i, dtype=torch.int64, device=device),
             torch.as_tensor(j, dtype=torch.int64, device=device))
            for i, j in indices]