tl; dr: no.
We have already had a question here about HEIF and free implementations thereof, the upshot of which was that the use of LGPLv3 for libheif grants a licence for any patents held or used under licence by the author. Unfortunately, it's not at all clear that the libheif authors have the rights so to use the patents embodied by HEIF, so it's not at all clear that their use by libheif users is licensed.
But the bigger problem is that your software is GPLv2, and libheif is LGPLv3. The FSF has held that those two licences are incompatible, and others agree. So all patent issues aside, unless one of you changes your licensing arrangements, the two bodies of code cannot be combined.
I note that your question introduces subtleties like enabling HEIF support to be turned off at build time, and not shipping any binaries with it turned on. Whether that would improve the patent situation I cannot say, but I suspect that enough libheif-specific changes would have to be made to your codebase to enable HEIF to be meaningfully compiled-in on request that your code would become a derivative work of libheif, thus running you squarely into the licence compatibility issue. I also suspect, though with less grounds, that shoving the whole patent issue downstream like that will not endear you to distributors, who may just throw up their hands and decide not to touch your project until it's unquestionably patent-unencumbered.
Though, as ever, IANAL/IANYL, and you should seek your own legal advice before relying on it.