One idea would be that when CC collects local variables, it stores them as a series of nodes (like xml). The root node of a function would contain the local variables that are always available. Child nodes would be created for each { } pair containing the variables declared there (child nodes would, of course, have their own child nodes for { } pairs within them).
When CC is called, it would start by looking for all the variables in the current child node, then traverse up, collecting the tokens in each parent node until it reaches the root node.
I think the hard part with this method would how to keep track of which child node the user is currently typing in.
(I am still working on reading Code::Blocks' source, so I do not yet know enough to be able to tell if implementing this method would be feasible.)