Does this work? Could be rewritten as: 

    if b_idx is not None: