There are many issues that can cause this. R/R fob batteries is good first step and you can rule out car battery as well.
Start by keeping it simple, don't have your cell phone near the car. Phones with wifi on, in same hand as fob, etc can interfere.
Next, if there are any non-essential after market accessories installed, radios, bluetooths, etc. start by pulling the fuses to see if it's one of them.
Something local is most likely interfering with the RFID. I knew one person who had a RFID blocking wallet and had "intermittent fob not detected issues". Found out it was when he had the wallet and fob in the same hand, as an example.
Otherwise, since you know 100% it works in the glove box slot (detected) that verifies you can use the Owner's Manual instructions to re-program it back to the car. I'd suggest the Long Method of wiping them all out and then adding them back in 1 thru 4 as applicable. If you have the option for Automatic Memory Recall (Seats, etc) then only fobs 1 & 2 will work for that feature. If you do the short method of Add Another, it may make it 3, or 4. But, you could do the Add Another Short Method to see if it works then since it's much quicker procedure.
A final issue could be a check of the RCDL (Remote Control Door Lock) Module in the the top of the dash above the glove box. I'd recommend taking it to someone good with a scan tool (Tech II) at that point to investigate.
Hope others may have additions and corrections to help out
