Suppose I download an open source project from GitHub and modify the code further.
Can I patent this code and restrict others to reuse my "modified" code?
You can not patent code. You can only patent an invention which is implemented in your code. An invention is a new and unique way of doing something. Most of all, it must be something nobody did before. If anyone used the same technique which you describe in your patent, that's called prior art and invalidates your patent. So trying to get a patent on something somebody else invented and implemented in code would be futile.
But what you could do is try to get a patent on the stuff you added, if it by itself is patent-worthy. For example, if you invent a new and innovative approach to encoding videos, you could get a patent for that video codec and create a fork of VLC Media Player with an implementation of that codec built-in. That VLC fork would be licensed under GPLv2, but would also be affected by your patent. You could demand patent fees from anyone who distributes it in a country which recognizes software patents.
This is usually contrary to the spirit of Open Source, which is why many of the newer open source licenses have special clauses regarding software patents. For example, the Apache License 2.0 and the GPLv3 say that the licensor also grants a patent license for any patents which apply to the software.
You cannot patent code. The US patent office is delivering patents for "algorithms" but even the validity of those is contested, and they won't be enforceable in many countries. Furthermore, to be eligible for a patent, a work must be novel and non-obvious. If you start from an existing project and your modification of its algorithm nature is not significant enough, then your work won't be eligible for a patent.
I won't describe them here, but modern licenses (in particular GPL v3) have some terms preventing patent abuse.