Yes, you're correct that you can use static variables to maintain state between function calls. Perhaps it's better to say that lambda expressions enable you to share state between a function and its caller, because a static local variable is only accessible from the scope of the function in which it is defined.
You also caught me saying "the first 20 prime numbers". I realized later that I said this. Thanks for the correction.