def ignore_this_demo(args, demo_reward, t, last_extras):
    """In some cases, we should filter out demonstrations.

    Filter for if t == 0, which means the initial state was a success.
    Also, for the bag envs, if we end up in a catastrophic state, I exit
    gracefully and we should avoid those demos (they won't have images we
    need for the dataset anyway).
    """
    ignore = (t == 0)

    # For bag envs.
    if 'exit_gracefully' in last_extras:
        assert last_extras['exit_gracefully']
        return True

    # Another bag env.
    if (args.task in ['bag-color-goal']) and demo_reward <= 0.5:
        return True

    # Another bag env. We can get 0.5 reward by touching the cube only (bad).
    if args.task == 'bag-items-easy' and demo_reward <= 0.5:
        return True

    # Harder bags: ignore if (a) no beads in zone, OR, (b) didn't get both
    # items. Need separate case because we could get all beads (0.5) but only
    # one item (0.25) which sums to 0.75. However, we can also get both items
    # (0.5) and a few beads (e.g., 0.1) which sums to 0.6.
    if args.task == 'bag-items-hard':
        return (last_extras['zone_items_rew'] < 0.5 or
                last_extras['zone_beads_rew'] == 0)

    return ignore