A note on the validity of the density matrix expansion