To my ear, the two E chords are a temporary, direct modulation to E major. They take advantage of the root movement from G to F# and also serve to set up the bridge. (Note that jazz and blues allow for the interpretation of a major key even when the minor seventh is present.)
In a different context, E might be interpreted as IV borrowed from B major, but while it is literally the case, I don't think it explains the overall sound any better than just thinking in terms of root movement. Similarly, other "standard" explanations, like treating the F#7 as a common-tone chord with E, I think also stretch the theory too far.
 Although Jazz, blues, and popular music harmonies are often in line with the common practice model of tonality, the don't adhere strictly to it. The presence of the ♭7 in major is a good example: it is frequently treated as a consonance rather than a dissonance. The bridge of this piece is a perfect example. The underlying harmony is E7, but the whole section is clearly perceived as E major rather than A major, as common practice tonality would demand.