A condition for a subspace of B(H) to be an ideal