A density consistency approach to the inverse Ising problem