If the immigration service don’t know that you lose your previous H1B status, maybe you can do H1B transfer from your previous company (first h1B sponsor) to current new company without leaving USA, but normally when you apply for H1B transfer you need provide copy of your last Pay check or pay stub in order to show continuous employment. If they know there is big gap between 2 employments, you have to leave USA and come back with a valid H1B visa. Since you have to have a “nonimmigration status” to transfer to another “ nonimmigration status”. AOS (pending I485) is not a nonimmigration status.