Linearly scaling direct method for accurately inverting sparse banded matrices